package com.example.hsh.homefragment.utils;

import android.content.Context;
import android.content.SharedPreferences;
import android.support.annotation.StringDef;

import com.example.hsh.homefragment.model.GlobalSettings;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

/**
 * Created by HSH on 2016/12/26.
 */

public class SharedPreferenceUtil {

    public static final String SETTING_OF_GLOBAL = "setting_of_global";

    @StringDef({SETTING_OF_GLOBAL})
    @Retention(RetentionPolicy.SOURCE)
    public @interface Settings{}

    public SharedPreferences getSharedPreferences(Context context, @Settings String settingName) {
        return context.getSharedPreferences(settingName, Context.MODE_PRIVATE);
    }

    public float getScreenDensity(Context context) {
        return getSharedPreferences(context, SETTING_OF_GLOBAL).getFloat(GlobalSettings.SCREEN_DENSITY, 0);
    }

    public void setScreenDensity(Context context, float density) {
        getSharedPreferences(context, SETTING_OF_GLOBAL).edit().putFloat(GlobalSettings.SCREEN_DENSITY, density).apply();
    }

    public float getScreenWidth(Context context) {
        return getSharedPreferences(context, SETTING_OF_GLOBAL).getFloat(GlobalSettings.SCREEN_WIDTH, 0);
    }

    public void setScreenWidth(Context context, float width) {
        getSharedPreferences(context, SETTING_OF_GLOBAL).edit().putFloat(GlobalSettings.SCREEN_WIDTH, width).apply();
    }

    public float getScreenHeight(Context context) {
        return getSharedPreferences(context, SETTING_OF_GLOBAL).getFloat(GlobalSettings.SCREEN_HEIGHT, 0);
    }

    public void setScreenHeight(Context context, float height) {
        getSharedPreferences(context, SETTING_OF_GLOBAL).edit().putFloat(GlobalSettings.SCREEN_HEIGHT, height).apply();
    }
}
